package com.theatre.userservice.config;

import com.theatre.userservice.interceptor.JwtTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private JwtTokenInterceptor jwtTokenInterceptor;
    @Value("${upload.base-dir}")
    private String uploadBaseDir;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtTokenInterceptor)
                .addPathPatterns("/user/**", "/role/**", "/shop/**", "/audit/**", "/publisher/**", "/shop/**", "/script/**", "/script-category/**","/cart/**")   // 需要校验的路径
                .excludePathPatterns("/user/login", "/user/insert","/user/guest-login");  // 不需要校验的路径
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String fullPath = System.getProperty("user.dir") + "/" + uploadBaseDir + "/";
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:" + fullPath); // ✅ 静态资源映射单独配置
    }
}
